import { request, ListData, SearchParamsData, baseAdminAPI } from '@/service/request'

export interface UserDataProps {
  id: number
  username: string
  nickName: string
  phoneNumber: string
  picture: string
  type: string
  createdAt: string
  latestLoginAt: string
  isFrozen: boolean
}

export async function fetchUsers(payload: SearchParamsData) {
  const rawData = await request<ListData<UserDataProps>>(baseAdminAPI + '/users', 'get', payload)
  return rawData.data
}

// 冻结用户 ids  '1' 或 '1,2,3'
export async function frozeUser(payload: { ids: string }) {
  await request(baseAdminAPI + '/users/froze', 'post', payload)
}

export async function unFrozeUser(payload: { ids: string }) {
  await request(baseAdminAPI + '/users/unFroze', 'post', payload)
}

export async function getCount() {
  const rawData = await request<{ count: number; active: number }>(baseAdminAPI + '/users/getCount', 'get')
  return rawData.data
}

export async function getMonthlyCount() {
  const rawData = await request<any[]>(baseAdminAPI + '/users/getMonthlyCount', 'get')
  return rawData.data
}
